
<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

// function to parse a video
$JO_channel="1";
if(isset($_REQUEST["JO_channel"]) && $_REQUEST["JO_channel"]!=""){$JO_channel=$_REQUEST["JO_channel"];}
if(isset($_REQUEST["JO_episode"]) && $_REQUEST["JO_episode"]!=""){$JO_episode=$_REQUEST["JO_episode"];}
if(isset($_REQUEST["JO_part"]) && $_REQUEST["JO_part"]!=""){$JO_part=$_REQUEST["JO_part"];}
$iteminpage=10;
$query="SELECT
        `show`.`key`,
        `show`.`subject`,
        `show`.description,
        `show`.viewer,
        `show`.episode,
        `show`.image,
        `show`.note,
        `show`.log,
        `show`.`insert`,
        `show`.`update`,
        `show`.`delete`,
        (select GROUP_CONCAT(show_detail.part  separator ';') FROM show_detail where show_detail.`delete` is null and show_detail.`show`=`show`.`key`) as parts
        FROM
        `show`
        WHERE `show`.`delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"")."
        GROUP BY
        `show`.`key`
        ORDER BY
        `show`.episode desc

            ";
    $recordSet = JO_query( $query );
    $totalepisode=$recordSet->num_rows;
?>
<script type="text/javascript">
function showsubtvp(url,startepi,currentpi,totalpi) {
    var cpage="";
    if((parseInt(startepi)==1) && (parseInt(currentpi)==1)){
	}else{
	if((parseInt(startepi)-2)>=-1){
        if((parseInt(startepi))==parseInt(currentpi)){
            cpage+="<a href=\"#\" onclick=\"showsubtvp('JO_51_subTV.php?startepisode="+(parseInt(startepi)-3)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)-3)+"','"+currentpi+"','"+totalpi+"'); return false;\"><img src=\"JO_80_image/2(2).png\" width=\"16px\" title=\"Previous\" style=\"padding-top: 4px;\"/> </a>";
        }else{
           cpage+="<a href=\"#\" onclick=\"showsubtvp('JO_51_subTV.php?startepisode="+(parseInt(startepi)-2)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)-2)+"','"+currentpi+"','"+totalpi+"'); return false;\"><img src=\"JO_80_image/2(2).png\" width=\"16px\" title=\"Previous\" style=\"padding-top: 4px;\"/> </a>";
        }
    }
	}
    if((parseInt(startepi)+2)<parseInt(totalpi)){
        if((parseInt(startepi)+3)==parseInt(currentpi)){
            cpage+="<a href=\"#\" onclick=\"showsubtvn('JO_51_subTV.php?startepisode="+(parseInt(startepi)+3)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)+3)+"','"+currentpi+"','"+totalpi+"'); return false;\"> <img src=\"JO_80_image/1(2).png\" width=\"16px\" title=\"Next\" style=\"padding-top: 4px;\"/></a>";
        }else{
            cpage+="<a href=\"#\" onclick=\"showsubtvn('JO_51_subTV.php?startepisode="+(parseInt(startepi)+2)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)+2)+"','"+currentpi+"','"+totalpi+"'); return false;\"> <img src=\"JO_80_image/1(2).png\" width=\"16px\" title=\"Next\" style=\"padding-top: 4px;\"/></a>";
        }
    }
	document.getElementById("tvpage").innerHTML=cpage;
    if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest(); }
    else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
        xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    document.getElementById("subtv").innerHTML=xmlhttp.responseText;
                }
            }

    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    //



}
function showsubtvn(url,startepi,currentpi,totalpi) {
    var cpage="";
    if((parseInt(startepi)-2)>=-1){
        if((parseInt(startepi))==parseInt(currentpi)){
            cpage+="<a href=\"#\" onclick=\"showsubtvp('JO_51_subTV.php?startepisode="+(parseInt(startepi)-3)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)-3)+"','"+currentpi+"','"+totalpi+"'); return false;\"><img src=\"JO_80_image/2(2).png\" width=\"16px\" title=\"Previous\" style=\"padding-top: 4px;\"/> </a>";
        }else{
            cpage+="<a href=\"#\" onclick=\"showsubtvp('JO_51_subTV.php?startepisode="+(parseInt(startepi)-2)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)-2)+"','"+currentpi+"','"+totalpi+"'); return false;\"><img src=\"JO_80_image/2(2).png\" width=\"16px\" title=\"Previous\" style=\"padding-top: 4px;\"/> </a>";
        }
    }
	if(parseInt(currentpi)==parseInt(totalpi) && (parseInt(startepi)+3)==parseInt(totalpi)){
		cpage+="<div style=\"width: 16px!important;padding: 0px;margin: 0px;height: 16px !important;float:right\"></div>";
	}else{
		if((parseInt(startepi)+2)<parseInt(totalpi)){
			if((parseInt(startepi)+3)==parseInt(currentpi)){
				cpage+="<a href=\"#\" onclick=\"showsubtvn('JO_51_subTV.php?startepisode="+(parseInt(startepi)+3)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)+3)+"','"+currentpi+"','"+totalpi+"'); return false;\"> <img src=\"JO_80_image/1(2).png\" width=\"16px\" title=\"Next\" style=\"padding-top: 4px;\"/></a>";
			}else{
				cpage+="<a href=\"#\" onclick=\"showsubtvn('JO_51_subTV.php?startepisode="+(parseInt(startepi)+2)+"<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','"+(parseInt(startepi)+2)+"','"+currentpi+"','"+totalpi+"'); return false;\"> <img src=\"JO_80_image/1(2).png\" width=\"16px\" title=\"Next\" style=\"padding-top: 4px;\"/></a>";
			}
		}else{
			//cpage+="<img src=\"JO_80_image/1(2).png\" width=\"16px\" title=\"Next\" style=\"padding-top: 4px;\"/>";
			cpage+="<div style=\"width: 16px!important;padding: 0px;margin: 0px;height: 16px !important;float:right\"></div>";
		}
	}
    document.getElementById("tvpage").innerHTML=cpage;
    if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest(); }
    else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
        xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    document.getElementById("subtv").innerHTML=xmlhttp.responseText;
                }
            }

    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    //
}
function SetAction(channel,episode,part){
    document.getElementById("JO_channel").value=channel;
    document.getElementById("JO_episode").value=episode;
    document.getElementById("JO_part").value=part;
    frm_tvshow.submit();
}
</script>
<div class="JO_page">

	<h1>JukeOn TV Show</h1>
        <h2>&nbsp;</h2>
        <h3>&nbsp;</h3>
</div>
<form
    id="frm_tvshow"
    name="frm_tvshow"
    method="post"
    action="?JO_unit=50_TV"
    >
    <input type="hidden" id="JO_channel" name="JO_channel" value=""/>
    <input type="hidden" id="JO_episode" name="JO_episode" value=""/>
    <input type="hidden" id="JO_part" name="JO_part" value=""/>
</form>
<div class="JO_relative" style="width: 960px">
     <div class="JO_left" style="width: 240px;">
        <div class="JO_bar_240" style="height:240px">
            <h1>New Jukeon</h1>
            <h2>1</h2>
            <div id="JO_notice_0" class="JO_photo_240_72" style="position: absolute; left: 4px; top: 28px; ">

                <a href="?JO_unit=50_TV&JO_channel=1">

                    <img src="http://jukeon.vn/JO/JO_80_image/JO_45_jukeon.png" style="background-image: none;">

                    <h3>JukeOn Vietnam</h3>

                    <h4></h4>

                    <p>Yeah1 TV<br/>SCTV4<br/>VTC4</p>

                </a>

            </div>
            <div id="JO_notice_1" class="JO_photo_240_72" style="position: absolute; left: 4px; top: 108px; ">

                <a href="?JO_unit=50_TV&JO_channel=2" >

                    <img src="http://jukeon.vn/JO/JO_80_image/JO_44_ktoU.png" style="background-image: none;">

                    <h3>KtoU</h3>

                    <h4></h4>

                    <p>HTV2</p>

                </a>

            </div>
            <div id="JO_notice_2" class="JO_photo_240_72" style="position: absolute; left: 4px; top: 188px; ">

                <a href="?JO_unit=50_TV&JO_channel=3" >

                    <img src="http://jukeon.vn/JO/JO_80_image/JO_43_KMusic.png" style="background-image: none;">

                    <h3>Kmusic</h3>

                    <h4></h4>

                    <p>VBC</p>

                </a>

            </div>
        </div>
     </div>
    <div class="JO_bar_720 JO_left">
        <?
        if(!isset($_REQUEST["episode"])){
            $page=1;
            if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
            $query="SELECT

                `show`.`key`,
                `show`.`subject`,
                `show`.description,
                `show`.viewer,
                `show`.episode,
                `show`.image,
                `show`.note,
                `show`.log,
                `show`.`insert`,
                `show`.`update`,
                `show`.`delete`,
                (select GROUP_CONCAT(show_detail.part  separator ';') FROM show_detail where show_detail.`delete` is null and show_detail.`show`=`show`.`key`) as parts
                FROM
                `show`
                WHERE `show`.`delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"")."
                GROUP BY
                `show`.`key`
                ORDER BY
                `show`.episode desc
                Limit ".(($page-1)*$iteminpage).",".$iteminpage."
                    ";
            $recordSet = JO_query( $query );
            ;
            if(($totalepisode%$iteminpage)!=0) {$numpages=(int)($totalepisode/$iteminpage)+1;}
            else                {$numpages=$totalepisode/$iteminpage;}
        ?>
            <h1>Jukeon TV Show</h1>
            <h2>
            <?

                if($numpages>1){
                    if($page>2){
                    ?>
                        <a href="#" onclick="sendurl('1');">?</a>
                    <?
                    }
                    if($page>1){
                    ?>
                        <a href="#" onclick="sendurl('<?=($page-1)?>');">?</a>

                    <?
                    }
                    if($page-4>1) echo "...";
                    for($i=$page-4;$i<=($page-1);$i++){
                        if($i>0){
                        ?>
                        <a href="#" onclick="sendurl('<?=$i?>');"><?=$i?></a>
                        <?
                        }
                    }
                    echo  "<b style='color=#ffffff;'>".$page."</b>";
                    for($i=$page+1;$i<=($page+4);$i++){
                        if($i<=$numpages){
                        ?>
                        <a href="#" onclick="sendurl('<?=$i?>');"><?=$i?></a>
                        <?
                        }
                    }
                    if($page+4<$numpages) echo "...";
                    if($page<$numpages){
                    ?>
                        <a href="#" onclick="sendurl('<?=($page+1) ?>');">?</a>
                    <?
                    }
                    if($page<($numpages-1)){
                    ?>
                        <a href="#" onclick="sendurl('<?=$numpages ?>');">?</a>

                    <?
                    }

                }
                 ?>
            </h2>
<!--            <div style="padding: 4px 0px 4px 0px;text-align: center">
                <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Tbw7fZ5NQAs&amp;hl=en&amp;fs=1"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/Tbw7fZ5NQAs&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></object>
            </div>-->

            <div style="

/*                 border: 1px solid #A8A8A8;*/
                 padding: 0px;margin: 0px; width: 704px;">
                <div style="
/*                    border-bottom: 1px solid #FCFCFC;*/
/*                    border-bottom-width: 1px;*/
/*                    border-bottom-style: solid;*/
/*                    border-bottom-color: #FCFCFC;
                    border-top: 1px solid #F9F9F9;
                    border-left: 1px solid #F9F9F9;
                    border-right: 1px solid #F9F9F9;*/
/*                    background-color: #e8e8e8;*/

                    padding: 0px 0px 0px 0px;margin: 0px ;width: 704px;

                    "
                    >
<!--                    <h1 style="font-weight: bold;width: 694px;padding: 0px;margin: 0px;border-bottom: 1px solid #A8A8A8;">
                        &nbsp;&nbsp;Jukeon T?p <?//=30+$i?>-Các Phần Liên Quan
                    </h1>-->
                    <div style="
                         padding:0px;
                         margin: 0px 0px 0px 0px;
                         width: 704px;
/*                         border-top: 1px solid #f9f9f9;*/
                         display: inline-block
                         ">
                        <div style="padding: 0px;">
                            <?

                            if($recordSet->num_rows){ while($record = $recordSet -> fetch_array( )){

                            ?>

							<div style="padding: 4px;width: 342px !important;position: relative;float: left" >

                                <span style="display: inline-block;
                                    _display: inline;
                                    _zoom: 1;
                                    padding: 4px;
                                    background: white;
                                    overflow: hidden;
                                    border: 1px solid lightGrey;
                                    border-radius: 3px;
                                    -moz-border-radius: 3px;
                                    -webkit-border-radius: 3px;
                                    _line-height: 0;">
<!--                                    image-->

                                        <a href="<?=(($record["parts"]>0)?("?JO_unit=50_TV&episode=".$record["episode"].(isset($JO_channel)?("&JO_channel=".$JO_channel):"")):"#i")?>">
                                        <img src="<?=$record["image"]?>" width="120px" height="90px;"/></a>
<!--                                    <span style="padding: 0 4px;
                                                font-weight: normal;
                                                font-size: 11px;
                                                -moz-border-radius: 3px;
                                                -webkit-border-radius: 3px;
                                                border-radius: 3px;
                                                background-color: black;
                                                color: white!important;
                                                height: 14px;
                                                line-height: 14px;
                                                opacity: 0.75;
                                                filter: alpha(opacity=75);
                                                display: -moz-inline-stack;
                                                display: inline-block;
                                                vertical-align: top;
                                                zoom: 1;margin-top: 0;
                                                margin-right: 0;
                                                position: absolute;
                                                left: 5px;
                                                bottom: 9px;">
                                        length
                                            0:31
                                    </span>-->
                                    <div style="
                                                font-weight: normal;
                                                font-size: 11px;
                                                width: 204px;
                                                height: 14px;
                                                line-height: 14px;
                                                opacity: 0.75;
                                                filter: alpha(opacity=75);
                                                display: inline-block;
                                                vertical-align: top;
                                                margin-right: 0;
                                                position: absolute;
                                                left: 140px;
                                                bottom: 9px;">
                                        <?
                                         if(isset ($record["parts"])){
                                             $parts=array();
                                             $parts=explode(";", $record["parts"]);
                                             natsort($parts);
                                             $linkpart="";
                                             $numpart=0;
                                             foreach ($parts as $value){
                                                if($value!=""){
                                                    $linkpart.="<a href='?JO_unit=50_TV&episode=".$record["episode"]."&part=".$value.(isset($JO_channel)?("&JO_channel=".$JO_channel):"")."'>Phần ".$value."</a>&nbsp;&nbsp;";
                                                    $numpart++;
                                                }
                                             }
                                             if($numpart>1) echo $linkpart;
                                             else echo "<a href='?JO_unit=50_TV&episode=".$record["episode"].(isset($JO_channel)?("&JO_channel=".$JO_channel):"")."'>Xem</a>";
                                         }else echo "�ang C?p Nh?t";
                                        ?>
                                    </div>
                                </span>


                                <div style="width: 204px;padding:0px;position: absolute;top:4px;right:4px;">
<!--                                <div style="width: 546px;float: right;">-->
                                    <span style="font-weight: bold;padding: 4px 0px 0px 0px;margin: 0px;border-bottom: 0px;background-color: inherit;">
<!--                                        title-->
                                    <a href="<?=(($record["parts"]>0)?("?JO_unit=50_TV&episode=".$record["episode"]).(isset($JO_channel)?("&JO_channel=".$JO_channel):""):"#i")?>">
                                        <?=$record["subject"]?></a>
                                    </span><br/>
                                    <span>
<!--                                        description-->
                                        <?=$record["description"]?>
                                    </span>
                                </div>
                            </div>

                            <?
                            }
                            }else echo "Chương trình đang cập nhật, xin vui lòng quay lại sau.";
                            ?>

                        </div>


                    </div>


                </div>

            </div>
            <?
        }else{
            $part=1;
            $episode=$_REQUEST["episode"];
            if(isset($_REQUEST["part"])) $part=$_REQUEST["part"];
            $query="select (select count(part)from show_detail,`show` where `show`.`key`=show_detail.`show` and show_detail.`delete` is null and `show`.episode='".$episode."' ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"").") as numpart
                    ,(select max(`show`.episode) from `show` where `show`.`delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"").") as lastepisode
                    ,`show`.*,show_detail.`url`,show_detail.`part`
                    from `show`,show_detail
                    where `show`.`delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"")."
                        and show_detail.`delete` is null
                        and `show`.`key`=show_detail.`show`
                        and `show`.episode='".$episode."'
                   order by `part` asc
                    ";
            $recordSet = JO_query( $query );
            if($recordSet->num_rows) $record = $recordSet -> fetch_array( );
            $contentyoutube=html_entity_decode($record["url"]);
            $description=$record["description"];
            $lastepisode=$record["lastepisode"];
            ?>
            <h1><?=$record["subject"]?></h1>

            <div style="border: 1px solid #A8A8A8;padding: 0px;margin: 4px 4px 4px 4px; width: 694px !important;">
                <div style="
                     position: relative;
                    border-bottom: 1px solid #FCFCFC;
                    border-bottom-width: 1px;
                    border-bottom-style: solid;
                    border-bottom-color: #FCFCFC;
                    border-top: 1px solid #F9F9F9;
                    border-left: 1px solid #F9F9F9;
                    border-right: 1px solid #F9F9F9;
                    background-color: #e8e8e8;
                    padding: 4px 0px 0px 0px;margin: 0px ;width: 692px;
                    "
                    >
                    <h1 style="font-weight: normal;width: 690px;padding: 0px;margin: 0px;border-bottom: 1px solid #A8A8A8;">
                        &nbsp;&nbsp;B?n �ang Xem <?=$record["subject"]?><?=($record["numpart"]>1)?("-Phần "):""?> <span id="chapcurrent"><?=($record["numpart"]>1)?(isset($_REQUEST["part"])?$_REQUEST["part"]:"1"):""?></span>
                    </h1>
                    <?
                    if($record["numpart"]>1){
                    ?>
                    <h2 style="width: 325px !important;">
                        <a href="#i" onclick="changeif('<?=(str_replace("+", "%20", $record["url"]))?>','<?=$record["part"]?>');">
                            Phần <?=$record["part"]?>
                        </a>
                        <?
                        if($recordSet->num_rows) while($record = $recordSet -> fetch_array( )){
                            if($record["part"]==$part)$contentyoutube=html_entity_decode($record["url"]);
                        ?>
                        - <a href="#i" style="z-index: 10" onclick="changeif('<?=(str_replace("+", "%20", $record["url"]))?>','<?=$record["part"]?>');">
                            Phần <?=$record["part"]?>
                        </a>
                        <?
                        }
                        ?>
                    </h2>
                    <?
                    }
                    ?>
                    <div style="width: 350px !important;height: 20px"></div>
                    <div style="padding:4px 4px 4px 4px;margin: 0px 0px 0px 0px;width: 684px;border-top: 1px solid #f9f9f9;">
                        <div style="padding: 4px 0px 4px 0px;width: 682px;text-align: center;" id="ifyoutube">
                            <!--678px-->

                                <?
                                if($contentyoutube==""){
                                    echo "T?p N�y Hi?n �ang �u?c C?p Nh?t. B?n Vui L�ng Quay L?i Sau.";
                                }else {
                                    echo $contentyoutube;

                                }
                                ?>

                        </div>
                        <center><? echo isset($description)?"$description":"";?></center>

                    </div>


                </div>

            </div>

            <!--==========================================-->
            <?


            ?>
            <div style="border: 1px solid #A8A8A8;padding: 0px;margin: 8px 4px 8px 4px; width: 694px !important;">
                <div style="
                    border-bottom: 1px solid #FCFCFC;
                    border-bottom-width: 1px;
                    border-bottom-style: solid;
                    border-bottom-color: #FCFCFC;
                    border-top: 1px solid #F9F9F9;
                    border-left: 1px solid #F9F9F9;
                    border-right: 1px solid #F9F9F9;
                    background-color: #e8e8e8;
                    padding: 4px 0px 0px 0px;margin: 0px ;width: 692px;
                    "
                    >
                    <h1 style="font-weight: normal;width: 690px;padding: 0px;margin: 0px;border-bottom: 1px solid #A8A8A8;">
                        &nbsp;&nbsp;Những Tập Liên Quan
                    </h1>
                    <h2 style="width: 328px">
                        <?

                            $querynum="
                                        select tmp.iterator,tmp.numrows,tmp.episode from
                                            (SELECT          @i:=@i+1 AS iterator,
                                                            `show`.`key`,
                                                            `show`.`subject`,
                                                            `show`.description,
                                                            `show`.viewer,
                                                            `show`.episode,
                                                            `show`.image,
                                                            `show`.note,
                                                            `show`.log,
                                                            `show`.`insert`,
                                                            `show`.`update`,
                                                            `show`.`delete`,
                                                            (select count(`key`) from `show` where `delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"").") as numrows
                                                            FROM
                                                            `show`,(SELECT @i:=0) foo
                                                            WHERE `show`.`delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"")."
                                                            GROUP BY
                                                            `show`.`key`
                                                            ORDER BY
                                                            `show`.episode asc
                                            )as tmp where ".(($lastepisode!=$_REQUEST["episode"])?("tmp.episode='".$_REQUEST["episode"]."'"):(" tmp.iterator='".($totalepisode-2)."'"))."
                                    ";

                        $recordSetnum = JO_query( $querynum );
                        if($recordSetnum->num_rows) $recordnum = $recordSetnum -> fetch_array( );
                        ?>
                        <span id="tvpage">
                            <?
                            if($recordnum["iterator"]!=1 && $totalepisode>3){
                            ?>
                            <a href="#i" onclick="showsubtvp('JO_51_subTV.php?startepisode=<?=($lastepisode!=$_REQUEST["episode"])?($recordnum["iterator"]-3):($totalepisode-5)?><?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','<?=($lastepisode!=$_REQUEST["episode"])?($recordnum["iterator"]-3):($totalepisode-5)?>','<?=($lastepisode!=$_REQUEST["episode"])?($recordnum["iterator"]):($totalepisode)?>','<?=($recordnum["numrows"])?>'); return false;">
                                <img src="JO_80_image/2(2).png" width="16px" title="Previous"
                                     style="padding-top: 4px;"/>
                            </a>
                            <?
                            }
                            if(($lastepisode!=$_REQUEST["episode"]) && ($recordnum["iterator"]+2)<$totalepisode && $totalepisode>3){
                            ?>
                            <a href="#i" onclick="showsubtvn('JO_51_subTV.php?startepisode=<?=($recordnum["iterator"]+2)?><?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>','<?=($recordnum["iterator"]+2)?>','<?=($recordnum["iterator"])?>','<?=($recordnum["numrows"])?>'); return false;">
                                <img src="JO_80_image/1(2).png" width="16px" title="Next"
                                     style="padding-top: 4px;"/>
                            </a>
                            <?
                            }else echo "<div style=\"width: 16px!important;padding: 0px;margin: 0px;height: 16px !important;float:right\"></div>";
                            ?>
                        </span>
                    </h2>

                    <div style="width: 350px !important;height: 20px !important"></div>
                   <div style="padding:4px 0px 4px 4px;margin: 0px 0px 0px 0px;width: 682px;border-top: 1px solid #f9f9f9;display: inline-block;">
                         <div id="subtv" style="padding: 4px 0px 4px 4px; width: 674px">
                            <?
                            $curentepi=isset ($recordnum["episode"])?$recordnum["episode"]:0;
                            $query="SELECT
                                        `show`.`key`,
                                        `show`.`subject`,
                                        `show`.description,
                                        `show`.viewer,
                                        `show`.episode,
                                        `show`.image,
                                        `show`.note,
                                        `show`.log,
                                        `show`.`insert`,
                                        `show`.`update`,
                                        `show`.`delete`,
                                        (select GROUP_CONCAT(show_detail.part  separator ';') FROM show_detail where show_detail.`delete` is null and show_detail.`show`=`show`.`key` ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"").") as parts
                                        FROM
                                        `show`
                                        WHERE `show`.`delete` is null ".(isset($JO_channel)?(" and `show`.channel=".$JO_channel):"")."
                                        and `show`.episode>".(($lastepisode!=$_REQUEST["episode"])?$_REQUEST["episode"]:$curentepi)."
                                        GROUP BY
                                        `show`.`key`
                                        ORDER BY
                                        `show`.episode asc
                                        limit 2

                                            ";

                                $recordSet = JO_query( $query );
                                if($recordSet->num_rows) while($record = $recordSet -> fetch_array( )){

                            ?>
                            <div style="padding: 0px 0px 4px 0px;width: 336px;float: left;">
                                <span style="display: inline-block;
                                    _display: inline;
                                    _zoom: 1;
                                    padding: 4px;
                                    background: white;
                                    overflow: hidden;
                                    border: 1px solid lightGrey;
                                    border-radius: 3px;
                                    -moz-border-radius: 3px;
                                    -webkit-border-radius: 3px;
                                    _line-height: 0;">
                                    <a href="<?=(($record["parts"]>0)?("?JO_unit=50_TV&episode=".$record["episode"].(isset($JO_channel)?("&JO_channel=".$JO_channel):"")):"#i")?>">
                                        <img src="<?=$record["image"]?>" width="120px" height="90px;"/>
                                    </a>
                            <!--                                    <span style="padding: 0 4px;
                                                font-weight: normal;
                                                font-size: 11px;
                                                -moz-border-radius: 3px;
                                                -webkit-border-radius: 3px;
                                                border-radius: 3px;
                                                background-color: black;
                                                color: white!important;
                                                height: 14px;
                                                line-height: 14px;
                                                opacity: 0.75;
                                                filter: alpha(opacity=75);
                                                display: -moz-inline-stack;
                                                display: inline-block;
                                                vertical-align: top;
                                                zoom: 1;margin-top: 0;
                                                margin-right: 0;
                                                position: absolute;
                                                left: 5px;
                                                bottom: 9px;">
                                        3:25
                                    </span>-->
                                    <div style="
                                                font-weight: normal;
                                                font-size: 11px;
                                                width: 204px;
                                                height: 14px;
                                                line-height: 14px;
                                                opacity: 0.75;
                                                filter: alpha(opacity=75);
                                                display: inline-block;
                                                vertical-align: top;
                                                margin-right: 0;
                                                position: absolute;
                                                left: 136px;
												padding: 0px;
                                                bottom: 9px;">
                                        <?
                                         if(isset ($record["parts"])){
                                             $parts=array();
                                             $parts=explode(";", $record["parts"]);
                                             natsort($parts);
                                             $linkpart="";
                                             $numpart=0;
                                             foreach ($parts as $value){
                                                if($value!=""){
                                                    $linkpart.="<a href='?JO_unit=50_TV&episode=".$record["episode"]."&part=".$value.(isset($JO_channel)?("&JO_channel=".$JO_channel):"")."'>Phần ".$value."</a>&nbsp;&nbsp;";
                                                    $numpart++;
                                                }
                                             }
                                             if($numpart>1) echo $linkpart;
                                             else echo "<a href='?JO_unit=50_TV&episode=".$record["episode"].(isset($JO_channel)?("&JO_channel=".$JO_channel):"")."'>Xem</a>";
                                         }else echo "Đang Cập Nhật";
                                        ?>
                                    </div>
                                </span>

                                <div style="width: 204px; padding: 0px;position: absolute;top:0px;left: 136px;">

                                    <span style="font-weight: bold;padding: 0px;margin: 0px;border-bottom: 0px;background-color: inherit;">
                                        <a href="<?=(($record["parts"]>0)?("?JO_unit=50_TV&episode=".$record["episode"].(isset($JO_channel)?("&JO_channel=".$JO_channel):"")):"#i")?>">
                                         <?=$record["subject"]?>
                                        </a>
                                    </span><br/>
                                    <span>
                                        <?=$record["description"]?>
                                    </span>
                                </div>

                            </div>
                            <?
                                }

                            ?>

                        </div>


                    </div>


                </div>

            </div>
            <?

            }
            ?>
    </div>
</div>
<script>


function changeif(vurl,chap){
   if(chap==document.getElementById("chapcurrent").innerHTML){alert("Bạn đang xem phần này."); return;}
    var objyoutube="";
    objyoutube+="<object width=\"678px\">";
    objyoutube+="<param name=\"allowFullScreen\" value=\"true\">";
    objyoutube+="<param name=\"allowscriptaccess\" value=\"always\">";
    //objyoutube+=unescape(vurl).replaceAll("+", " ");
    objyoutube+=unescape(vurl);
    objyoutube+="</object>";
    document.getElementById("ifyoutube").innerHTML=objyoutube;
    document.getElementById("chapcurrent").innerHTML=chap;
}
String.prototype.replaceAll = function(
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );

// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )

// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}

// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
}
function sendurl(p){
    if(p>1)
        location=("?JO_unit=50_TV<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>&Page="+p);
    else
        location=("?JO_unit=50_TV<?=(isset($JO_channel)?("&JO_channel=".$JO_channel):"")?>");
}
</script>
